# -*- coding: utf-8 -*-
class DeliveryOrder < ActiveRecord::Base
  #attr_accessor :tax_amount,:cost_amount

  has_many :delivery_order_details ,:dependent => :destroy  #级联删除子表
  has_many :delivery_order_hxes    ,:dependent => :destroy  #级联删除子表
  #belongs_to :from_warehouse, :class_name => "Warehouse" , :foreign_key => :to_warehouse_id
  #belongs_to :to_warehouse, :class_name => "Warehouse" , :foreign_key => :to_warehouse_id
  belongs_to :sale_order
  belongs_to :warehouse
  belongs_to :employee
  belongs_to :order_type
  belongs_to :department
  belongs_to :company
  belongs_to :customer

  def self.findAllDelivery conditionsStr,conditionsHash,paramsHash
    begin
      find(
        :all,
        :conditions => [conditionsStr,conditionsHash],
        :include => [:sale_order,:delivery_order_details],
        :offset => paramsHash[:offset],
        :limit => paramsHash[:limit],
        :order => 'delivery_orders.updated_at DESC'
      )
    rescue Exception => e
      logger.info e
    end
  end

  def self.countAllDelivery conditionsStr,conditionsHash
    begin
      count(
        :all,
        :conditions => [conditionsStr,conditionsHash],
        :include => [:sale_order,:delivery_order_details]
      )
    rescue Exception => e
      logger.info e
    end
  end
end
